
package clientapp;

import java.io.*;
import javax.microedition.lcdui.*;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;

/**
 *
 */
public class ControllerMIDlet extends javax.microedition.midlet.MIDlet {
    private xmlHandler handler;
    private SelectafdView select;
    
    private SelectoplView oplView;
    private SelectieList sl;
    private clientSenderSPPtest cs;
    
    
  
    public void startApp() {
        
        select = new SelectafdView(this);
        oplView = new SelectoplView(this);
        sl = new SelectieList(this);
        handler = new xmlHandler(this);
        
                    try
    {
        
      SAXParserFactory factory = SAXParserFactory.newInstance();
      SAXParser saxParser = factory.newSAXParser();
      InputStream is = getClass().getResourceAsStream("/HHS.xml");
      InputSource inputSource = new InputSource(is);
      saxParser.parse(is, handler);
      
    }
    catch(Exception ex) {
        System.out.println(ex);}

        getMainView();

    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
        
        notifyDestroyed();
    }

    public void getSelectView() {
         Display.getDisplay(this).setCurrent(select);
    }


    
    public void getMainView() {
        Display.getDisplay(this).setCurrent(new MainView(this));
    }


    public void getoplView() {
        Display.getDisplay(this).setCurrent(oplView);
    }

        public void getSelectieList() {
        Display.getDisplay(this).setCurrent(sl);
    }

    public void setSelectView(){


        for (int i = 0; i < handler.hhs.getAfdelingSize(); i++) {
            handler.afdeling = handler.hhs.getAfdeling(i);
            select.append(handler.afdeling.getAfdNaam(), null);

        }

    }


    public void setOpleiding(int index) {
        handler.afdeling = handler.hhs.getAfdeling(index);
              for (int j = 0; j < handler.afdeling.getOpleidingSize(); j++) {
                handler.opleiding = handler.afdeling.getOpleiding(j);
                String opl  = handler.opleiding.getNaam();
                oplView.append(opl, null);
        }
    }

     public void bekijkOpl(int opleiding){

                handler.opleiding = handler.afdeling.getOpleiding(opleiding);
                String opl  = handler.opleiding.toString();
         String selectie = "Afdeling: " + handler.afdeling.getAfdNaam() + "\n" + opl;
         sl.append(selectie);
     }


}

